package com.nacosclient.nacosclient;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import feign.Client;
import feign.Feign;
import feign.form.spring.SpringFormEncoder;
import feign.hystrix.HystrixFeign;
import feign.okhttp.OkHttpClient;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;

import java.util.Arrays;
public class FeignBuildApi {
	private Client client=new OkHttpClient();
	private ObjectFactory<HttpMessageConverters> objectFactory=()->new HttpMessageConverters(Arrays.asList(new FastJsonHttpMessageConverter()));
	private ObjectFactory<HttpMessageConverters> objectFactory1=()->new HttpMessageConverters(Arrays.asList(new StringHttpMessageConverter()));

	public FeignClientService2 getClientTest(){
		return Feign.builder().client(client)
				.encoder(new SpringFormEncoder())
				.decoder(new SpringDecoder(objectFactory1))
				.contract(new SpringMvcContract())
				.target(FeignClientService2.class,"http://localhost:3004/userserver/");
	}

	public FeignClientService2 getClientTest1(){
		return HystrixFeign.builder().client(client)
				.encoder(new SpringFormEncoder())
				.decoder(new SpringDecoder(objectFactory1))
				.contract(new SpringMvcContract())
				.target(FeignClientService2.class,"http://localhost:3005/",new FeignClientService2FallBack());
	}


}
